﻿//decode *.lrc
//by CHikari
//v0.1
function lrc2Title(){
    var actItem = app.project.activeItem;    												//The activeItem in after effects
    if(actItem == null || !(actItem instanceof CompItem)) {    							//If the Item doesn't exists or isn't a comp
        alert("An active composition required.");						//show a message and return
        return;
    }

    var laycoll = actItem.layers;   //get layerCollection laycoll
    laycoll.addText("lyrics");
    var curlayer = actItem.layer(1);
    
    var lrc= File.openDialog("select the modified LRC file", "*.lrc");  
    lrc.open("r", "TEXT", "????");
    
    var reg = new RegExp("\\[(\\d{2}:\\d{2}\\.\\d{2})\\]");
    
    while(!(lrc.eof)){
        var line = lrc.readln();
        var time = reg.exec(line);
        if(time != null){
            //laycoll.addText(currentFormatToTime(time[1], 60)+" || " + time[1]);   //using for debug
            curlayer.sourceText.setValueAtTime(currentFormatToTime(time[1], 60), line.replace(time[0], ""));
        }
    }
    
}

lrc2Title ();